/*
 * 项目名称:    wms-app-xinpu
 * 创建人员:    DongPeng
 * 创建时间:    2023-02-28
 * copyright(c) 2022 无锡星智数服科技有限公司
 */
package org.jeecg.modules.dock.handler;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.dock.config.GenericUtil;
import org.jeecg.modules.dock.config.JsonUtils;
import org.jeecg.modules.dock.entity.dto.request.SapBaseRequestDTO;
import org.jeecg.modules.dock.entity.dto.response.SapBaseResponseDTO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * sap处理抽象类
 *
 * @author DongPeng
 * @version 1.0.0
 * @date 2023-02-28
 * @description 类描述
 */
@Slf4j
public abstract class AbstractSapDataHandler<T extends SapBaseRequestDTO> implements SapDataHandler {

    public Class<T> supportClass() {
        return (Class<T>) GenericUtil.getSuperClassGenericType(this.getClass());
    }

    public List<T> decode(List<String> list) {
        return list.stream().map(str -> JsonUtils.toBean(str, supportClass())).collect(Collectors.toList());
    }

    @Override
    public List<? extends SapBaseResponseDTO> handleData(List<String> data) {
        return doHandle(decode(data));
    }

    public abstract List<? extends SapBaseResponseDTO> doHandle(List<T> data);

}
